package com.wyth.lottery.code;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Typeface;

import com.wyth.lottery.R;


public class BitmapT {
    public static Bitmap bitmaptest1(Context context) {
        int w = 631;
        int h = 706;
        Bitmap mbmpTest = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(mbmpTest);
        canvas.drawColor(Color.WHITE);
        Paint paint = new Paint();
        paint.setColor(Color.BLACK);
        paint.setAntiAlias(true);
        paint.setStyle(Paint.Style.FILL_AND_STROKE);
        setSize1(canvas, paint);
        setSize2(canvas, paint);
        setSize3(canvas, paint);
        Resources resources = context.getResources();
        Bitmap bitmap = BitmapFactory.decodeResource(resources, R.drawable.zj);
        Bitmap bitmap1 = zoomImage(bitmap, 150);
        canvas.drawBitmap(bitmap1, 415, 428, paint);
        return mbmpTest;
    }

    private static void setSize1(Canvas canvas, Paint paint) {
        paint.setTextSize(35);
        paint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));//字体
        canvas.drawText("双色球", 245, 55, paint);//品名
        paint.setTextSize(25);
        paint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL));//字体
        canvas.drawText("投注方式: 单式投注   期号：2017119", 30, 113, paint);//品名
        canvas.drawText("销售时间： 2017-10-08 16:48:23", 30, 149, paint);//品名
        canvas.drawText("注数：5   面额：10元", 30, 185, paint);//品名
    }

    private static void setSize2(Canvas canvas, Paint paint) {
        paint.setTextSize(35);
        paint.setTypeface(Typeface.create(Typeface.MONOSPACE, Typeface.BOLD));//字体
        canvas.drawText("A:09 16 21 25 26 31+14 1倍", 30, 251, paint);//品名
        canvas.drawText("B:02 03 04 06 13 26+33 1倍", 30, 287, paint);//品名
        canvas.drawText("C:03 05 11 17 29 31+15 1倍", 30, 323, paint);//品名
        canvas.drawText("D:03 08 15 27 29 32+13 1倍", 30, 359, paint);//品名
        canvas.drawText("E:07 12 16 21 25 27+07 1倍", 30, 395, paint);//品名
    }

    private static void setSize3(Canvas canvas, Paint paint) {

        paint.setTextSize(25);
        paint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL));//字体
        canvas.drawText("站编号： 652315", 30, 448, paint);//品名
        canvas.drawText("流水号： 10254521188", 30, 488, paint);//品名
        canvas.drawText("开奖： 2017-10-10 21:15", 30, 528, paint);//品名
        canvas.drawText("站地址： 金角大厦 ", 30, 568, paint);//品名
    }

    public static Bitmap zoomImage(Bitmap bgimage, double newWidth) {
        float width = bgimage.getWidth();
        float height = bgimage.getHeight();
        float scaleWidth = (float) (newWidth / bgimage.getWidth());
        // 创建操作图片用的matrix对象
        Matrix matrix = new Matrix();
        // 缩放图片动作
        matrix.postScale(scaleWidth, scaleWidth);
        Bitmap bitmap = Bitmap.createBitmap(bgimage, 0, 0, (int) width, (int) height, matrix, true);
        return bitmap;
    }
}
